package bigDecimal;

import java.math.BigDecimal;

/**
 * @author by panstark
 * @description
 * @notice
 * @date 2020/11/20
 */
public class BigDecimalCalcu {

    public static void main(String[] args) {
        //calculate();
        //devidBigDecimal();

        for (int i = 0; i <10 ; i++) {
            calculate2();
        }

    }


    public static void calculate2(){
        BigDecimal arrangeNum = new BigDecimal(322.00);
        //BigDecimal arrangeNum = new BigDecimal(6);
        BigDecimal mainNum = new BigDecimal(39840);
        BigDecimal conversationRate = new BigDecimal(6);
        BigDecimal arrangeMainNum = arrangeNum.multiply(conversationRate).divide(BigDecimal.ONE, 0, BigDecimal.ROUND_HALF_UP);

        //BigDecimal deliveryNum = new BigDecimal(1932);

        BigDecimal deliveryRate = arrangeMainNum.divide(mainNum,7,BigDecimal.ROUND_HALF_UP);

        //20637120
        BigDecimal amount = new BigDecimal(20637120.00);
        BigDecimal itemAmount = amount.multiply(deliveryRate).setScale(2,BigDecimal.ROUND_HALF_UP);

        System.out.println("ItemAmount:"+itemAmount);
    }




    public static void calculate(){

        BigDecimal arrangeNum = new BigDecimal(1400);
        Integer currencyAmountScale = 2;

        BigDecimal mainNum = new BigDecimal(234000);
        BigDecimal conversionRate = new BigDecimal(6);
        BigDecimal arrangeMainNum = arrangeNum.multiply(conversionRate).divide(BigDecimal.ONE, 0, BigDecimal.ROUND_HALF_UP);
        System.out.println("arrangeMainNum："+arrangeMainNum);

        BigDecimal arrageRate = arrangeMainNum.divide(mainNum,7,BigDecimal.ROUND_HALF_UP);
        System.out.println("arrageRate："+arrageRate);

        BigDecimal amount = new BigDecimal(13754520);
        BigDecimal deliveryAmount = amount.multiply(arrageRate).setScale(currencyAmountScale,BigDecimal.ROUND_HALF_UP);
        System.out.println("deliveryAmount："+deliveryAmount);
        BigDecimal dealAmount = new BigDecimal(13754520);
        BigDecimal deliveryDealAmount =dealAmount.multiply(arrageRate).setScale(currencyAmountScale,BigDecimal.ROUND_HALF_UP);
        System.out.println("deliveryDealAmount"+deliveryDealAmount);

    }

    public static void devidBigDecimal(){
        BigDecimal tow = new BigDecimal(2);
        BigDecimal six = new BigDecimal(6);
        BigDecimal result = tow.divide(six,2,BigDecimal.ROUND_HALF_UP);
        System.out.println(result);
    }
}
